﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRMBiz.CalculateInterest;

namespace CRMWeb.Pages.Test
{
    public partial class SACCCalculator : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Label2.Text = "Term (in " + ddlRepayment.SelectedItem.Text.ToString() + "):";
        }

        protected void btnCalculateByTerm_Click(object sender, EventArgs e)
        {
            Label2.Visible = true;
            txtTerm.Visible = true;

            double loanAmount = Convert.ToDouble(txtLoanAmount.Text);
            int term = Convert.ToInt16(txtTerm.Text);
            int repaymentOpt = Convert.ToInt16(ddlRepayment.Text);


            double establishFeePC = Convert.ToInt16(txtEstbFee.Text);
            double monthlyFeePC = Convert.ToInt16(txtMnthFee.Text);

            DateTime settlementDate = Convert.ToDateTime(txtFirstDate.Text);
            DateTime firstPaymentDate = Convert.ToDateTime(txtFirstPaymentDate.Text);

            double totEstablishmentFee = SACC.GetTotalEstablishmentFee(loanAmount, establishFeePC);
            double totMonthlyFee = SACC.GetTotalMonthlyFee(loanAmount, term, repaymentOpt, monthlyFeePC, settlementDate, firstPaymentDate);

            txtTotEstbFee.Text = totEstablishmentFee.ToString();
            txtTotMnthFee.Text = totMonthlyFee.ToString();

            txtTotFee.Text = (totEstablishmentFee + totMonthlyFee).ToString();


            DataTable dtSchedule = new DataTable();
            dtSchedule = SACC.SACCCalculateByTerm(loanAmount, term, repaymentOpt, totEstablishmentFee, totMonthlyFee, settlementDate, firstPaymentDate);
            dvSchedule.DataSource = dtSchedule;
            dvSchedule.DataBind();
        }
    }
}